package com.wx.chapter8.homework08;

/**
 * ClassName:SavingsAccount
 * Package :com.wx.chapter8.homework08
 * Description :
 *
 * @Author : coder_mu
 * @Create : 2023/5/29 - 17:42
 */
public class SavingsAccount extends BankAccount {
    private int count;//免手续费次数
    private double rate;//利率

    //计算每个月利息
    public double earnMonthlyInterest(double banlance) {
        count = 3;
        return banlance * rate;//余额乘以利率即为利息
    }

    //存款
    @Override
    public void deposit(double amount) {
        if (count > 0) {//判断免手续费次数，如果大于零，说明还可以免费办理业务
            super.deposit(amount);
            count--;
        } else {
            super.deposit(amount - 1);
        }
    }

    //取款
    @Override
    public void withdraw(double amount) {
        if (super.getBalance() <= 0) {
            System.out.println("余额不足");
        } else {
            if (count > 0) {
                super.withdraw(amount);
                count--;
            } else {
                super.withdraw(amount + 1);
            }
        }
    }

    public SavingsAccount(int balance, int count, double rate) {
        super(balance);
        this.count = count;
        this.rate = rate;
    }

    public SavingsAccount(int balance) {
        super(balance);
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public double getRate() {
        return rate;
    }

    public void setRate(double rate) {
        this.rate = rate;
    }
}
